package com.spn.blog.api.component;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;


@Component
@Slf4j
public class MyCallBack implements RabbitTemplate.ConfirmCallback, RabbitTemplate.ReturnsCallback {

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        if (ack)
            log.info("======交换机接收到消息=====id:{}", correlationData.getId());
        else
            log.info("======交换机无法接收到消息=====id:{}，原因:{}", correlationData.getId(), cause);
    }

    @Override
    public void returnedMessage(ReturnedMessage returned) {
        log.info("======已退回消息=====内容:{}，路由key为:{}", returned.getMessage().getBody(), returned.getRoutingKey());
    }
}
